# Contributor: Luca Weiss <luca@z3ntu.xyz>
# Maintainer: Luca Weiss <luca@z3ntu.xyz>
pkgname=libcamera
pkgver=0_git20211109
pkgrel=5
_commit="f2a1817275db8fb77acb5f2771b7577be8642194"
pkgdesc="Linux camera framework"
url="https://libcamera.org/"
arch="all"
license="LGPL-2.1-or-later AND GPL-2.0-or-later"
depends_dev="
	boost-dev
	eudev-dev
	glib-dev
	gnutls-dev
	gst-plugins-bad-dev
	qt5-qtbase-dev
	"
# upstream calls 'date' with a non-POSIX option so we pull in coreutils
makedepends="$depends_dev
	coreutils
	doxygen
	graphviz
	gtest-dev
	libevent-dev
	linux-headers
	meson
	py3-jinja2
	py3-ply
	py3-sphinx
	py3-yaml
	qt5-qttools-dev
	"
subpackages="
	$pkgname-dev
	$pkgname-doc
	qcam
	$pkgname-gstreamer
	$pkgname-v4l2
	$pkgname-raspberrypi
	$pkgname-tools
	"
source="https://dev.alpinelinux.org/archive/libcamera/libcamera-$_commit.tar.gz
	0001-fix-unit-tests-build.patch
	0002-use-sensor-s-controls.patch
	0003-smaller-resolutions.patch
	build.patch
	gtest.patch
	qcam.desktop
	"
options="!check" # gstreamer tests fail
builddir="$srcdir/libcamera"

_disturl="dev.alpinelinux.org:/archive/$pkgname/"

snapshot() {
	clean
	deps
	mkdir -p "$srcdir" && cd "$srcdir"
	git clone https://git.libcamera.org/libcamera/libcamera.git --recursive
	cd libcamera && git checkout $_commit && cd -
	tar czvf $SRCDEST/$pkgname-$_commit.tar.gz libcamera
	rsync --progress -La $SRCDEST/$pkgname-$_commit.tar.gz $_disturl
}

build() {
	abuild-meson \
		-Dv4l2=true \
		-Dwerror=false \
		. output
	meson compile ${JOBS:+-j ${JOBS}} -C output
}

check() {
	meson test --no-rebuild -C output --print-errorlogs
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output
}

qcam() {
	amove usr/bin/qcam

	install -Dm644 -t "$subpkgdir"/usr/share/applications "$srcdir"/qcam.desktop
}

gstreamer() {
	amove usr/lib/gstreamer-1.0
}

v4l2() {
	amove usr/lib/v4l2-compat.so
}

raspberrypi() {
	amove usr/share/libcamera/ipa/raspberrypi
	amove usr/libexec/libcamera/raspberrypi_ipa_proxy
}

tools() {
	amove usr/bin/cam
	amove usr/bin/lc-compliance
}

sha512sums="
a3dd355eee982f8baec1a537ed022b8aabba0c6ea3f31053d70b23a1e92fb8327113c794c77c9a318943f12f46045b779fe736e09514f3663b47443c7396a399  libcamera-f2a1817275db8fb77acb5f2771b7577be8642194.tar.gz
869447f535f486a3a6d4b49631a628843fe9fd892e7d69df2d3afb9ee5eda43027504364b3abe5aea070a7ddb9bf6b5bb9c10b9aa8a9cbf9c19e4a3da5735b6b  0001-fix-unit-tests-build.patch
c1ebd6f3c46a252021cd52796a281a84b390a77609459697ebdbaf1489b6f7bacd71ad29951446af7e6d7e40054ec6b21b90375ae7c52e9f30d2fb9926fe1e20  0002-use-sensor-s-controls.patch
d396b15ff02ce1eacc15fa55f069c0c84ef8adf65fb9f391352025a7f3bd7076b70144e408a4eef61c56372988d1765b800a8290686df3d37aa89fc9cd4d0ac7  0003-smaller-resolutions.patch
aab9ac6dd029d5cf661931f22c548b9dc0e692b98e7ba4827da7f54f996856df5f16ac372a17daac68b8d875f1f7d427a6826eb7dfba17222255a32323fc6200  build.patch
1c260217bc88cca8a64bfbcc658ea21c3941c711240475ac7a53c5b1e0fd951e910ba180989f9785c6dd240a4a21919af23158503f3d3e8e6556f32af6439b65  gtest.patch
22167a4eceb6d1b40b0b7c45fdf116c71684f5340de7f767535cb8e160ad9d2ae0f00cb3d461f73a344520a48a4641cf46226841d78bee06bfbfd2a91337f754  qcam.desktop
"
